package com.axjy.web;

import com.axjy.service.UserService;
import com.axjy.util.Log;
import com.axjy.util.Pager;
import com.axjy.web.dto.UserDto;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Created by asus on 2018/1/11.
 */
@RestController
@RequestMapping("/sys/user")
public class UserHandler {

    @Resource
    private UserService userService;

    @GetMapping("/search")
    public Pager search(@RequestParam(required = false,defaultValue = "0")Integer offset, @RequestParam(required = false,defaultValue = "4") Integer limit, UserDto dto){
        Pager pager=userService.searchPager(offset,limit,dto);
        return pager;
    }

    @PostMapping("/grant")
    public String grant(Integer userId,Integer roleId){
        String msg=null;
        try {
            userService.updateRole(userId, roleId);
            msg="用户授权成功！";
        }catch(RuntimeException ex){
            msg="用户授权失败！";
            Log.logger.error(msg,ex);
        }
        return msg;
    }


}
